using System.ServiceModel;
using NHConfiguration;

namespace NHServices.Model
{
    public class Proxy<T> where T : class
    {
        public static void Configure(ClientBase<T> client)
        {
            var section = Section.GetSection();
            if (section == null || section.EndPoints == null)
                return;

            var element = section.EndPoints.GetElementByKey(client.Endpoint.Contract.ConfigurationName);
            if (element == null)
                return;

            var certificate = element.GetClientCertificate();

            if (certificate != null)
                client.ClientCredentials.ClientCertificate.Certificate = certificate;
        }
    }
}